package cn.topcodes.tcsf.app.service.impl;

import cn.topcodes.tcsf.admin.commons.generic.GenericService;
import cn.topcodes.tcsf.app.domain.entity.AppConfig;
import cn.topcodes.tcsf.app.service.AppConfigService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author arjun
 * @date 2021-03-02 11:11
 */
@Service
public class AppConfigServiceImpl extends GenericService<AppConfig> implements AppConfigService {

    @Override
    public List<AppConfig> findAllByType(String type) {
        Assert.hasText(type, "'AppType' cannot be empty");
        return findAllByTypes(Collections.singleton(type));
    }

    @Override
    public List<AppConfig> findAllByTypes(Collection<String> types) {
        Assert.notEmpty(types, "'AppType' cannot be empty");
        Example example = this.buildExample();
        example.or().andIn(AppConfig.FIELD_TYPE, types);
        return this.findAll(example);
    }
}
